In [1]:
%%bash
pip install aplpy
pip install https://github.com/ericmandel/pyds9/archive/master.zip
In [2]:
%%bash
curl -O https://astropy.stsci.edu/data/galactic_center/gc_bolocam_gps.fits
curl -O https://astropy.stsci.edu/data/galactic_center/gc_2mass_k.fits
In [3]:
%matplotlib inline
import pylab as pl
In [4]:
from astropy.io import fits
In [5]:
# load the data (no headers, first extension by default)
# if there are extensions, fits.getdata('file.fits', ext=extension_number)
# if you want many extension, use fits.open('file.fits'), then access each independently
stellardata = fits.getdata('gc_2mass_k.fits')
In [21]:
# show the image: vmax sets the brightest displayed pixel
# cmap can be any of the valid matplotlib colormaps (pl.cm....)
pl.imshow(stellardata, cmap='viridis', vmax=1000)
Out[21]:
In [8]:
dustdata = fits.getdata('gc_bolocam_gps.fits')
In [9]:
pl.contour(dustdata)
Out[9]:
In [13]:
dustdata.shape, dustdata.flatten().shape
Out[13]:
In [14]:
np.any(np.isnan(dustdata))
Out[14]:
In [33]:
# subset of the data that is not nan
# implicitly flattens
non_nan_dustdata = dustdata[~np.isnan(dustdata)]
non_nan_dustdata = dustdata[np.isfinite(dustdata)]
non_nan_dustdata = np.compress(np.isfinite(dustdata.flatten()), dustdata.flatten())
len(non_nan_dustdata)
Out[33]:
In [17]:
pl.hist(dustdata[~np.isnan(dustdata)], bins=np.linspace(0,2,50))
Out[17]:
In [18]:
pl.contour(dustdata, levels=np.linspace(0.2, 10, 10))
Out[18]:
In [34]:
pl.figure(figsize=(12,12))
pl.imshow(stellardata, cmap='gray')
pl.contour(dustdata[100:-100, 100:-100], levels=np.linspace(0.2, 10, 10))
Out[34]:
In [35]:
import aplpy
In [40]:
%matplotlib nbagg
FF = aplpy.FITSFigure('gc_2mass_k.fits')
FF.show_grayscale(vmax=1000)
In [42]:
%matplotlib nbagg
FF = aplpy.FITSFigure('gc_2mass_k.fits')
FF.show_grayscale(vmax=1000)
# convention not generally needed, only for specific (CAR) FITS projections
FF.show_contour('gc_bolocam_gps.fits', convention='calabretta')
In [63]:
%matplotlib nbagg
FF = aplpy.FITSFigure('gc_2mass_k.fits')
FF.show_grayscale(vmax=1000)
# convention not generally needed, only for specific (CAR) FITS projections
FF.show_contour('gc_bolocam_gps.fits', convention='calabretta')
scalebar = FF.add_scalebar(0.1, label='0.1$^\circ$', color='orange')
FF.scalebar.set_corner('top right')
FF.scalebar.set_font_size(40)
FF.scalebar.set_font_weight('bold')
FF.scalebar.set_linewidth(4)
FF.scalebar.set_label('0.1$^\circ$')
In [68]:
import astroquery
from astropy import units as u
In [83]:
from astroquery.irsa import Irsa
from astroquery.vizier import Vizier
from astroquery.eso import Eso
In [90]:
Eso.ROW_LIMIT = 500
In [89]:
Eso.query_instrument('naco', help=True)
In [85]:
tbl = Eso.query_instrument('naco', target='Sgr A*')
tbl
Out[85]:
In [71]:
rslt = Irsa.query_region('Sgr A*', radius=10*u.arcmin, catalog='pt_src_cat')
#rslt
In [79]:
bright = rslt[rslt['k_m'] < 9]
In [93]:
%matplotlib nbagg
FF = aplpy.FITSFigure('gc_2mass_k.fits')
FF.show_grayscale(vmax=1000, invert=True)
# convention not generally needed, only for specific (CAR) FITS projections
FF.show_contour('gc_bolocam_gps.fits', convention='calabretta', colors=['r'])
scalebar = FF.add_scalebar(0.1, label='0.1$^\circ$', color='orange')
FF.scalebar.set_corner('top right')
FF.scalebar.set_font_size(40)
FF.scalebar.set_font_weight('bold')
FF.scalebar.set_linewidth(4)
FF.scalebar.set_label('0.1$^\circ$')
FF.show_markers(bright['ra'], bright['dec'])
Aside: running external code files
In [ ]:
%run file.py
%run -i file.py
execfile('file.py') # is equivalent to %run -i ...
Visualization Part 2: pyds9
In [5]:
import pyds9
from astropy.io import fits
In [6]:
DD = pyds9.DS9('mine')
In [7]:
DD.set('frame 1')
Out[7]:
In [8]:
DD.set_pyfits(fits.open('gc_2mass_k.fits'))
Out[8]:
In [9]:
DD.set('frame lock wcs')
DD.set('frame 2')
DD.set_pyfits(fits.open('gc_bolocam_gps.fits'))
Out[9]:
In [12]:
DD.set('single')
Out[12]:
For more information about ds9
xpa access points, see: ds9.si.edu/doc/ref/xpa.html